<script>
import StationInfo from "../../../../../components/business/station-info/index.vue";
import FixedFooter from "../../../../../components/business/fixed-footer/index.vue";
import {
  getAcceptInfoApi,
  mergeAcceptPassApi,
  mergeAcceptRefuse,
  mergeSubmitApi,
  mergeTmpApi
} from "../../../../../api/common/power-station";
import UButton from "../../../../../uni_modules/uview-ui/components/u-button/u-button.vue";
import UFormItem from "../../../../../uni_modules/uview-ui/components/u-form-item/u-form-item.vue";
import ModuleCard from "../../../../../components/business/module-card/index.vue";
import UForm from "../../../../../uni_modules/uview-ui/components/u-form/u-form.vue";
import imageUpload from "../../../../../components/base/image-upload/index.vue";
import {getCustomerEntryDetail} from "../../../../../api/customer";
import {basePowerStationInfo} from "../../constant/power-station";
import {getProjectCompanyByIdApi} from "../../../../../api/common/trader";
import {PLAN_TYPE_VALUE_TO_LABEL} from "../../../../../constant";
import {filerImageUrlParams} from "../../../../../static/utils/handleImage";
import {successBack} from "../../../../../static/utils/msg";
export default {
  name: "index",
  computed: {
    PLAN_TYPE_VALUE_TO_LABEL() {
      return PLAN_TYPE_VALUE_TO_LABEL
    }
  },
  components: {imageUpload, UForm, ModuleCard, UFormItem, UButton, StationInfo, FixedFooter },
  data() {
    return {
      id: '',
      baseInfo: basePowerStationInfo,
      formData: {
        gebImg: '',
        nbqYxImg: '',
        yxImg: '',
        yxOtherImg: '',
      },
      trader: {},
    }
  },
  methods: {
    mergeTmpApi,
    onLoad(options) {
      this.id = options.id
      this.getDetail(this.id);
    },
    // 获取详情
    async getDetail(id) {
      const { data } = await getAcceptInfoApi(id);
      this.baseInfo = data.entry;
    },
    // 根据ID查询代理商信息
    async getProjectCompanyById() {
      const { data } = await getProjectCompanyByIdApi(this.baseInfo?.distributorId);
      this.trader = data;
    },
    async merge() {
      const data = {
        id: this.id,
        generatorNo: this.baseInfo.generatorNo,
        ...this.formData,
      }
      await mergeSubmitApi(filerImageUrlParams(data))
      // 提示并网成功
      successBack('并网成功')
    },
    reject() {
      mergeAcceptRefuse({ id: this.id})
    },
    pass() {
      mergeAcceptPassApi({ id: this.id})
    },
    mergeTmp() {
      mergeTmpApi({ id: this.id})
    }
  }
}
</script>

<template>
  <view class="merge">
    <u-form
        labelPosition="left"
        labelWidth="100"
        :labelStyle="{'align-self': 'start', 'font-size': '14px'}"
    >
      <module-card title="电站基本信息">
        <u-form-item borderBottom label="产品编号">{{baseInfo.projectCode || '--'}}</u-form-item>
        <u-form-item borderBottom label="产品名称">{{baseInfo.projectName || '--'}}</u-form-item>
        <u-form-item borderBottom label="代理商名称">{{trader.name || '--'}}</u-form-item>
        <u-form-item borderBottom label="业主姓名">{{baseInfo.tenantName || '--'}}</u-form-item>
        <u-form-item borderBottom label="身份证号码">{{baseInfo.idCode || '--'}}</u-form-item>
        <u-form-item borderBottom label="安装地址">{{ baseInfo.province + baseInfo.city + baseInfo.area + baseInfo.address }}</u-form-item>
        <u-form-item borderBottom label="联系电话">{{baseInfo.mobile || '--'}}</u-form-item>
        <u-form-item borderBottom label="安装方案">{{ PLAN_TYPE_VALUE_TO_LABEL[baseInfo.schemeType] || '--' }}</u-form-item>
        <u-form-item borderBottom label="电站编码">{{baseInfo.mobile || '--'}}</u-form-item>
        <u-form-item borderBottom label="发电户号">{{baseInfo.a}}</u-form-item>
        <u-form-item borderBottom label="组件规格">{{baseInfo.componentSpec || '--'}}</u-form-item>
        <u-form-item borderBottom label="安装组件数量">{{baseInfo.componentNum || '--'}}</u-form-item>
        <u-form-item borderBottom label="通讯棒SN码">{{baseInfo.snOne || '--'}}</u-form-item>
        <u-form-item borderBottom label="通讯棒SN码">{{baseInfo.snTwo || '--'}}</u-form-item>
        <u-form-item borderBottom label="逆变器SN码">{{baseInfo.nbqSnOne || '--'}}</u-form-item>
        <u-form-item borderBottom label="逆变器SN码">{{baseInfo.nbqSnTwo || '--'}}</u-form-item>
      </module-card>
    </u-form>

    <u-form
        labelPosition="left"
        labelWidth="100"
        :labelStyle="{'align-self': 'start', 'font-size': '14px'}"
    >
      <module-card title="电站并网验收条款项">
        <view class="form-item-title">2.支架及组件安装照片</view>
        <u-row justify="space-between" gutter="10">
          <u-col span="4">
            <u-form-item :label="null" prop="details.a">
              <view>
                <image-upload v-model="formData.yxImg"/>
                <view class="form-item-subtitle"><text class="required">*</text>电站运行信息</view>
              </view>
            </u-form-item>
          </u-col>
          <u-col span="4">
            <u-form-item :label="null" prop="details.a">
              <view>
                <image-upload v-model="formData.nbqYxImg"/>
                <view class="form-item-subtitle"><text class="required">*</text>逆变器正常运行照片</view>
              </view>
            </u-form-item>
          </u-col>
          <u-col span="4">
            <u-form-item :label="null" prop="details.a">
              <view>
                <image-upload v-model="formData.yxOtherImg"/>
                <view class="form-item-subtitle"><text class="required">*</text>补充1</view>
              </view>
            </u-form-item>
          </u-col>
        </u-row>
        <u-row justify="space-between" gutter="10">
          <u-col span="4">
            <u-form-item :label="null" prop="details.gebImg">
              <view>
                <image-upload v-model="formData.gebImg"/>
                <view class="form-item-subtitle"><text class="required">*</text>补充2</view>
              </view>
            </u-form-item>
          </u-col>
          <u-col span="4"></u-col>
          <u-col span="4"></u-col>
        </u-row>
      </module-card>
    </u-form>
    <fixed-footer>
      <u-button
          type="primary"
          class="footer-btn"
          @click="merge"
      >并网</u-button>
      <!--<u-button-->
      <!--    class="footer-btn"-->
      <!--    @click="mergeTmp"-->
      <!--    style="width: 150px;margin-right: 15px"-->
      <!--&gt;暂存</u-button>-->
      <!--<u-button-->
      <!--    class="footer-btn"-->
      <!--    @click="reject"-->
      <!--    style="width: 150px;margin-right: 15px"-->
      <!--&gt;验收驳回</u-button>-->
      <!--<u-button-->
      <!--    type="primary"-->
      <!--    class="footer-btn"-->
      <!--    @click="pass"-->
      <!--&gt;验收通过</u-button>-->
    </fixed-footer>
  </view>
</template>

<style scoped lang="scss">
.footer-btn{
  margin: 0 0px;
  width: 100%;
}
.merge {
  padding-bottom: 80px;
}
</style>
